package com.ruoyi.good.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.good.domain.vo.GoodTypeVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.good.domain.TestGoodType;
import com.ruoyi.good.service.ITestGoodTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品类型Controller
 *
 * @author 程序员dd
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/good/type")
public class TestGoodTypeController extends BaseController {
    @Autowired
    private ITestGoodTypeService testGoodTypeService;

    /**
     * 查询商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('good:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestGoodType testGoodType) {
//        startPage();
//        List<TestGoodType> list = testGoodTypeService.selectTestGoodTypeList(testGoodType);
//        return getDataTable(list);

        startPage();
        List<GoodTypeVo> list = testGoodTypeService.getGoodCountByTestGoodTypeList(testGoodType);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('good:type:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestGoodType testGoodType) {
        List<TestGoodType> list = testGoodTypeService.selectTestGoodTypeList(testGoodType);
        ExcelUtil<TestGoodType> util = new ExcelUtil<TestGoodType>(TestGoodType.class);
        util.exportExcel(response, list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId) {
        return success(testGoodTypeService.selectTestGoodTypeByTypeId(typeId));
    }

    /**
     * 新增商品类型
     */
    @PreAuthorize("@ss.hasPermi('good:type:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestGoodType testGoodType) {
        return toAjax(testGoodTypeService.insertTestGoodType(testGoodType));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('good:type:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestGoodType testGoodType) {
        return toAjax(testGoodTypeService.updateTestGoodType(testGoodType));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('good:type:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return toAjax(testGoodTypeService.deleteTestGoodTypeByTypeIds(typeIds));
    }
}
